package ui;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.chart.*;
import javafx.scene.control.*;
import util.CapsJdbc;
import util.CapsRes;
import util.CapsTableView;

import java.net.URL;
import java.util.*;

public class LessonSelAna implements Initializable {

   @FXML
   private PieChart pieChart;

   @Override
   public void initialize(URL url, ResourceBundle rb) {
      this.dealQry();
   }

   private void dealQry() {
      String strSQL = "select b.name,count(*) as selcnt " +
              "from stu_lesson_rel a inner join stu b on a.sno=b.sno " +
              "group by b.name";
      CapsRes capsRes = CapsJdbc.execSQL(strSQL,null);
      List<PieChart.Data> dataList = new ArrayList<>(capsRes.getTtlNum());
      for (List<String> rec : capsRes.getRs()) {
         PieChart.Data o = new PieChart.Data(rec.get(0),Double.valueOf(rec.get(1)));
         dataList.add(o);
      }
      ObservableList<PieChart.Data> pieChartData =
              FXCollections.observableArrayList(dataList);
      pieChart.setData(pieChartData);
   }
}
